﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;

namespace BussinessLogicLayer
{
    class ThayDoiMatKhau :IThayDoiPass
    {
        #region Implementation of IThayDoiPass

        public bool KiemTraPass(string id, string pass)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;

            return tinChiEntities.USERs.First(user1 => user1.ID == id && user1.Password == pass) != null;
        }

        public bool ThayDoiPass(string id, string oPass, string nPass)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;

            USER user = tinChiEntities.USERs.First(user1 => user1.ID == id && user1.Password == oPass);
            if(user!=null)
            {
                user.Password = nPass;
                tinChiEntities.SubmitChanges();
            }
            return user != null;
        }

        #endregion
    }
}
